﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MaterialDesignThemes.Wpf;
using static System.Net.Mime.MediaTypeNames;
using static MaterialDesignThemes.Wpf.Theme;
using Application = System.Windows.Application;

namespace WpfApp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void FakerButton_OnClick(object sender, RoutedEventArgs e)
        {
            var jsonText = InputTextBox.Text;

            if (string.IsNullOrEmpty(jsonText))
            {

                return;
            }


            var fakeData = FakeJsonConverter.GenerateFakeData(jsonText);

            this.OutputTextBox.Text = fakeData;
        }






        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private  void CopyJsonButton_OnClick(object sender, RoutedEventArgs e) // 特例，可以这样使用async void
        {
            var fakeJsonText = OutputTextBox.Text;

            if (!string.IsNullOrEmpty(fakeJsonText))
            {

                Application.Current.Dispatcher.Invoke(() =>
                {
                    Clipboard.SetText(fakeJsonText);
                });
               
            }
        }



        private async Task CopyToClipboard(string text)
        {
            try
            {
                await Dispatcher.InvokeAsync(() =>
                {
                    try
                    {
                        // 使用 IDataObject 接口
                        var dataObject = new DataObject();
                        dataObject.SetData(DataFormats.Text, text);
                        dataObject.SetData(DataFormats.UnicodeText, text);

                        Clipboard.SetDataObject(dataObject, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"复制失败: {ex.Message}");
                    }
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show($"复制失败: {ex.Message}");
            }
        }





    }
}